/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilities;

import net.sourceforge.floggy.persistence.Comparator;
import net.sourceforge.floggy.persistence.Filter;
import net.sourceforge.floggy.persistence.FloggyException;
import net.sourceforge.floggy.persistence.ObjectSet;
import net.sourceforge.floggy.persistence.Persistable;
import net.sourceforge.floggy.persistence.PersistableManager;

/**
 *
 * @author Pedro Henrique
 */
public class FloggyUtility {
        ObjectSet os = null;
    public void delete(Persistable p, int id) {
        try {
            PersistableManager.getInstance().load(p, id);
            PersistableManager.getInstance().delete(p);
        } catch (FloggyException ex) {
            System.out.println("Não foi possivel excluir: " + p.toString() + " ID: " + id);
            ex.printStackTrace();
        }
    }

    public ObjectSet findAll(Persistable p){
        os = null;
        try {
            os = PersistableManager.getInstance().find(p.getClass(), null, null);
        } catch (FloggyException ex) {
            ex.printStackTrace();
        }
        return os;
     }
    
    public ObjectSet findFilter(Persistable p, Filter f){
        os = null;
        try {
            os = PersistableManager.getInstance().find(p.getClass(), f, null);
        } catch (FloggyException ex) {
            ex.printStackTrace();
        }
        return os;
     }   
    
    public ObjectSet findComparator(Persistable p, Comparator c){
        os = null;
        try {
            os = PersistableManager.getInstance().find(p.getClass(), null, c);
        } catch (FloggyException ex) {
            ex.printStackTrace();
        }
        return os;
     }     
    
    public ObjectSet findFilterAndComparator(Persistable p, Filter f, Comparator c){
        os = null;
        try {
            os = PersistableManager.getInstance().find(p.getClass(), f, c);
        } catch (FloggyException ex) {
            ex.printStackTrace();
        }
        return os;
     }    
    }
    
